<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
</head>

<body>
    <div id="info"></div>
    <script>
        function get(url, callBack) {
            // 1.创建一个xhr实例对象
            var xhr = new XMLHttpRequest();
            // 2.请求数据
            xhr.open('get', url);
            // 3.触发请求
            xhr.send(null);
            // 4.监听服务器数据返回
            xhr.onreadystatechange = function() {
                if (xhr.readyState === 4 && xhr.status === 200) {
                    var res = xhr.responseText;
                    var obj = JSON.parse(res);
                    callBack(obj);
                }
            };
        }
        get('http://www.liulongbin.top:3006/api/getbooks', function(res) {
            console.log(res);
            var div = document.getElementById('info');
            div.innerHTML = res.data.length;
        });
    </script>
</body>

</html>